package com.zmn.uac.client;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.uac.UacException;
import com.zmn.uuc.common.constant.DubboConsts;
import com.zmn.uuc.common.dio.user.UserBindMobileNoCaptchaByUserIdDIO;
import com.zmn.uuc.dubbo.interfaces.user.UserBindRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @title: 个人用户注册Dubbo接口
 * @author:Rananquan
 * @Date:2022/6/9 20:35
 */
@Slf4j
@Component
public class UserBindClient {

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    UserBindRemoteService userBindRemoteService;


    /**
     * 个人用户无验证码绑定手机号
     * @param dio
     * @return
     */
    public Boolean bindMobileNoCaptchaByUserId(UserBindMobileNoCaptchaByUserIdDIO dio){
        log.info("个人用户无验证码绑定手机号入参：[{}]",dio);
        ResponseDTO<Boolean> bindResponse = userBindRemoteService.bindMobileNoCaptchaByUserId(dio);
        if(!bindResponse.isSuccess()){
            log.error("个人用户无验证码绑定手机号请求失败，失败原因：{}",bindResponse.getMessage());
            throw new UacException(bindResponse.getMessage());
        }

        Boolean bindStatus = bindResponse.getData();
        log.info("个人用户无验证码绑定手机号返回response：{}",bindStatus);

        return bindStatus;
    }


    /**
     * 个人用户无验证码绑定手机号
     * @param userId 用户id
     * @return
     */
    public Boolean isBindMobileByUserId(Long userId){
        log.info("个人用户无验证码绑定手机号入参：{}",userId);
        ResponseDTO<Boolean> bindResponse = userBindRemoteService.isBindMobileByUserId(userId);
        if(!bindResponse.isSuccess()){
            log.error("个人用户无验证码绑定手机号请求失败，失败原因：{}",bindResponse.getMessage());
            throw new UacException(bindResponse.getMessage());
        }

        Boolean bindStatus = bindResponse.getData();
        log.info("个人用户无验证码绑定手机号返回response：{}",bindStatus);

        return bindStatus;
    }
}
